(function (vc) {
    vc.extends({
        propTypes: {
            emitChooseProduct: vc.propTypes.string,
            emitLoadData: vc.propTypes.string
        },
        data: {
            chooseStoreOrderCartInfo: {
                products: [],
                _currentProductName: '',
                shId: '',
                total: 0,
                records: 10,
                orderId: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('chooseStoreOrderCart', 'openChooseProductModel', function (_param) {
                $('#chooseStoreOrderCartModel').modal('show');
                $that._refreshChooseProductInfo();
                $that._loadAllProductInfo(1, 10, '');
            });
            vc.on('chooseStoreOrderCart', 'paginationPlus', 'page_event', function (_currentPage) {
                $that._loadAllProductInfo(_currentPage, 10);
            });
            vc.on('chooseStoreOrderCart', 'setProducts', function (_param) {
                $('#chooseStoreOrderCartModel').modal('show');
                $that._refreshChooseProductInfo();
                $that.chooseStoreOrderCartInfo.products = _param;
            });
        },
        methods: {
            _loadAllProductInfo: function (_page, _row, _name) {
                let param = {
                    params: {
                        page: _page,
                        row: _row,
                        prodName: $that.chooseStoreOrderCartInfo._currentProductName,
                        shopId: vc.getCurrentCommunity().shopId,
                        state: '',
                        orderId: $that.chooseStoreOrderCartInfo.orderId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderCart',
                    param,
                    function (json) {
                        let _productInfo = JSON.parse(json);
                        $that.chooseStoreOrderCartInfo.records = _productInfo.records;
                        $that.chooseStoreOrderCartInfo.total = _productInfo.total;
                        $that.chooseStoreOrderCartInfo.products = _productInfo.data;
                        vc.emit('chooseStoreOrderCart', 'paginationPlus', 'init', {
                            total: $that.chooseStoreOrderCartInfo.records,
                            currentPage: _page
                        });
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            chooseStoreOrderCart: function (_product) {
                if (_product.hasOwnProperty('name')) {
                    _product.productName = _product.name;
                }
                vc.emit($props.emitChooseProduct, 'chooseStoreOrderCart', _product);
                vc.emit($props.emitLoadData, 'listProductData', {
                    productId: _product.productId
                });
                $('#chooseStoreOrderCartModel').modal('hide');
            },
            queryProducts: function () {
                $that._loadAllProductInfo(1, 10, $that.chooseStoreOrderCartInfo._currentProductName);
            },
            _refreshChooseProductInfo: function () {
                $that.chooseStoreOrderCartInfo._currentProductName = "";
            }
        }
    });
})(window.vc);
